use std::collections::HashMap;

fn main() {
    let mut scores = HashMap::new();
    let mut scores2: HashMap<String, String> = HashMap::new();
    scores.insert("name", "小明");
    scores.insert("age", "10");
    scores.insert("a", "1");
    scores.insert("b", "2");

    // 不修改值，当键不存在时才插入
    scores.entry("a").or_insert("3");


    println!("=====访问HashMap=====");

    println!("name={}", scores["name"]);

    match scores.get("name") {
        Some(value) => println!("name={}", value),
        None => println!("none"),
    }

    println!("=====遍历HashMap=====");
    for (key, value) in scores {
        println!("{}: {}", key, value);
    }
}
